using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour
{
    public int ActiveCameraIndex = 3;
    public GameObject ActiveCamera;
    private GameObject[] cameras = new GameObject[8];

    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            var child = transform.GetChild(i).gameObject;
            cameras[i] = child;
        }
    }

    List<string> cameraName = new List<string> { "front", "left", "right", "back", "front-left", "front-right", "back-right", "back-left" };
    public void changeCamera(string name)
    {
        // 1-front 2-left 3-right 4-back 5-front-left 6-front-right 7-back-right 8-back-left
        if (cameraName.Contains(name))
        {
            ActiveCameraIndex = cameraName.IndexOf(name);

        }
        else
        {
            TextDialog.textDebug("There is no such a camera!", true) ;
        }
    }

    void chooseCamera()
    {
        foreach (var camera in cameras)
            camera.SetActive(false);
        cameras[ActiveCameraIndex].SetActive(true);
        ActiveCamera = cameras[ActiveCameraIndex];

        ActiveCamera.GetComponent<Skybox>().material = this.GetComponent<Skybox>().material;
    }

    // Update is called once per frame
    void Update()
    {
       
        // 1-front 2-left 3-right 4-back 5-front-left 6-front-right 7-back-right 8-back-left
        //if (Input.GetKeyDown(KeyCode.LeftControl))
        //{
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                ActiveCameraIndex = 0;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                ActiveCameraIndex = 1;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                ActiveCameraIndex = 2;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                ActiveCameraIndex = 3;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                ActiveCameraIndex = 4;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                ActiveCameraIndex = 5;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                ActiveCameraIndex = 6;
            }

            else if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                ActiveCameraIndex = 7;
            }
        //}

        chooseCamera();
    }
}
